package cn.lix.sc.rpc.client.handler;

import cn.lix.sc.rpc.impl.common.dto.EnhancedRpcResponse;
import cn.lix.sc.rpc.impl.common.dto.RpcResponse;
import cn.lix.sc.rpc.impl.common.exception.BaseException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 * @Author 木林森
 * @Date 2021/4/28
 */
@ResponseBody
@ControllerAdvice
public class ControllerExceptionHandler {

    private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());


    @ExceptionHandler(BaseException.class)
    public EnhancedRpcResponse exceptionHandler(BaseException e){
        log.error(e.getMessage());
        return EnhancedRpcResponse.error(e.toString());
    }

    @ExceptionHandler(Exception.class)
    public EnhancedRpcResponse exceptionHandler(Exception e){
        log.error("系统全局异常捕获：", e);
        return EnhancedRpcResponse.error("系统繁忙，请稍后重试");
    }

}
